package com.rttmall.shopbackend.utils;

import java.io.File;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Workbook;
import com.rttmall.shopbackend.exception.ServiceException;

public class ExportExcelUtil {
	
	/**
	 * 描述：根据文件路径获取项目中的文件
	 * @param fileDir 文件路径
	 * @return
	 * @throws Exception
	 */
	public  File getExcelDemoFile(String fileDir,HttpServletRequest request) throws Exception{
		File file = null;
		ServletContext context = request.getSession().getServletContext();
        String url = context.getRealPath("/WEB-INF/");
		
		file = new File(url+fileDir);
		if(!file.exists()){
			throw new ServiceException("模板文件不存在！");
		}
		return file;
	}

	
	/**
	 * 描述：设置简单的Cell样式
	 * @return
	 */
	public  CellStyle setSimpleCellStyle(Workbook wb){
		CellStyle cs = wb.createCellStyle();
		cs.setBorderBottom(CellStyle.BORDER_THIN); //下边框
		cs.setBorderLeft(CellStyle.BORDER_THIN);//左边框
		cs.setBorderTop(CellStyle.BORDER_THIN);//上边框
		cs.setBorderRight(CellStyle.BORDER_THIN);//右边框
		cs.setAlignment(CellStyle.ALIGN_CENTER); // 居中
		return cs;
	}

}
